<%@page import="crm.control.CustomerControl"%>
<%@page import="crm.model.Employees"%>
<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8"%>
<%@page import="crm.util.DateTime"%>
<%@page import="crm.control.RecepitControl"%>
<%@page import="crm.model.Customer"%>
<%@page import="crm.model.Recepit"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../resources/css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../resources/css/inner.css" type="text/css" media="screen" />
<style type='text/css'>
 a{font-size:12px; text-decoration:none; color:#70B300;}
</style>
		<title>添加日程</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script language="javascript">
		function check()
		{
		if(document.form1.theme.value=="")
		{
		alert("主题不能为空！");
		document.form1.theme.focus();
		return;
		}
		else if(document.form1.content.value=="")
		{
		alert("内容不能为空！");
		document.form1.content.focus();
		return;
		}
		else if(document.form1.customer.value=="")
		{
		alert("关联客户不能为空！");
		document.form1.customer.focus();
		return;
		}
		else
		{
		document.form1.submit();
		}
		
		}
		</script>
	</head>

	<body style='height:420px;'>
		<%
			Employees employees = (Employees) session.getAttribute("user");
			// Collection recepits = new ArrayList();
			// recepits=RecepitControl.getAllRecepits("","","","","","","",String.valueOf(employees.getId()),1,200);
			// Iterator iterator = recepits.iterator();
			// while(iterator.hasNext()) {
			// Recepit recepit = (Recepit)iterator.next();
			// System.out.print(recepit.getTitle());
		%>
		<form action="schedule_add_do.jsp" method="post" id="formId" name="form1">
			<table>
				<tr>
					<td>
						创建人姓名
					</td>
					<td>
						<input type="text" name="creater" value="<%=employees.getName()%>" readonly />
					</td>
				</tr>
				
				<tr>
					<td>
						时间
					</td>
					<td>
						<input type="text" name="create_time" value="<%=DateTime.DateTime()%>" readonly />
					</td>
				</tr>
				
				<tr>
					<td>
						主题
					</td>
					<td>
						<input type="text" name="theme"/>
					</td>
				</tr>
				
				<tr>
					<td>
						内容
					</td>
					<td>
						<input type="text" name="content">
					</td>
				</tr>
				
				
				<tr>
					<td>
						关联客户
					</td>
					<td>
						<!-- INPUT class="bton pointer" onclick=openSelect(1) type=button value=请选择关联客户 name=button> -->
						<DIV id=result>
							<DIV class="tit bgc_eee">
								<H2>
								</H2>
							</DIV>
							<DIV class=cont id=makeSureItem></DIV>
						</DIV>
						<DIV id=bg></DIV>
						<DIV class=hidden id=selectItem>
							<DIV class="tit bgc_ccc move" onmousedown=drag(event,this)>
								<H2 class=left>
									请选择客户:
								</H2><br/>
							</DIV>
							<DIV class=cls></DIV>
							<DIV class=cont>
								<DIV id=selectSub>
									<SELECT style="display: none; MARGIN-BOTTOM: 10px"
										onchange=showSelect(this.value)>
										<OPTION value=0 selected>
											第0层
										</OPTION>
									</SELECT>
									<div id=c00>
										<%
											List<Customer> customers = CustomerControl
													.getCustomersByEmployeeId(employees.getId());
											for (Customer c : customers) {
										%>
										<INPUT onclick=addPreItem() type=checkbox value="<%=c.getName()%>" name=ck00><%=c.getName()%>

										<%
											}
										%>
									</div>
								</div>
							</DIV>
							<br/>
							<div style='text-align: center; width:100%; display:block; height:20px;'>
								<A HREF='javascript:void(0);'  onclick=makeSure();>[确定]</A>
								<A HREF='javascript:void(0);' onclick=openBg(0);openSelect(0);>[取消]</A>
							</div>
							<DIV id=preview>
								<DIV class="tit bgc_eee c_999">
									<H2>
										您已选择的客户:
									</H2>
								</DIV>
								<DIV class=cont id=previewItem></DIV>
							</DIV>
						</DIV>
						<input type="hidden" name="customer" value="" />
					</td>
				</tr>
				
				<tr>
					<td style='text-align: center;' colspan='2'>
						<input type="button" class='button' value="提交" onClick="check()">&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="button" class='button' value="返回" onClick="window.top.location.href='schedule.jsp'">
					</td>
				</tr>
			</table>
		</form>
		<SCRIPT type=text/javascript>
/* ------使用说明----- */
/*
	添加城市方法：
	    添加组：找到id 是 "selectSub"中select标签下，添加option标签 value属性递增，找到 id 是 "selectSub",按照原有格式添加div,其id属性递增
	添加二级傅选矿选项
		复制 id 是 "selectSub" 下任意input标签，粘贴在需要添加的位置。
*/
var grow = $("selectSub").getElementsByTagName("option").length; //组数
var showGrow = 0;//已打开组
var selectCount = 0; //已选数量 
showSelect(showGrow);
var items = $("selectSub").getElementsByTagName("input");
//alert(maxItem);
//var lenMax = 2; 
//alert(1);
function $(o){ //获取对象
	if(typeof(o) == "string")
	return document.getElementById(o);
	return o;
}
function openBg(state){ //遮照打开关闭控制
	if(state == 1)
	{
		$("bg").style.display = "block";
		var h = document.body.offsetHeight > document.documentElement.offsetHeight ? document.body.offsetHeight : document.documentElement.offsetHeight;
	//alert(document.body.offsetHeight);
	//alert(document.documentElement.offsetHeight);
		$("bg").style.height = h + "px";
	}
	else
	{
		$("bg").style.display = "none";
	}	
}
function openSelect(state){ //选择城市层关闭打开控制
	if(state == 1)	
	{
		$("selectItem").style.display = "block";
		$("selectItem").style.left = ($("bg").offsetWidth - $("selectItem").offsetWidth)/2 + "px";
		$("selectItem").style.top = document.body.scrollTop + 100 + "px";		
	}
	else
	{
		$("selectItem").style.display = "none";
	}
}
function showSelect(id){
	for(var i = 0 ; i < grow ;i++)
	{
		$("c0" + i).style.display = "none";
	}
	$("c0" + id).style.display = "block";
	showGrow = id;
}
function open(id,state){ //显示隐藏控制
	if(state == 1)
	$(id).style.display = "block";
	$(id).style.diaplay = "none";
}
function addPreItem(){	
	$("previewItem").innerHTML = "";
	var len　= 0 ;
	var results = "";
	for(var i = 0 ; i < items.length ; i++)
	{
		if(items[i].checked == true)
		{
			//len++;
			//if(len > lenMax)
			//{
			//	alert("不能超过" + lenMax +"个选项！")
			//	return false;
			//}
			var mes = "<input type='checkbox' checked='true' value='"+ items[i].value +"' onclick='copyItem(\"previewItem\",\"previewItem\");same(this);'>" + items[i].value;
			var mes2 = items[i].value+"/";
			results+= mes2;
			$("previewItem").innerHTML += mes;
			//alert(items[i].value);
		}
		document.getElementsByName('customer')[0].value=results;
	}
}
function makeSure(){
	//alert(1);
	//$("makeSureItem").innerHTML = $("previewItem").innerHTML;
	openBg(0);
	openSelect(0);
	copyItem("previewItem","makeSureItem")	
}
function copyHTML(id1,id2){
	$(id2).innerHTML = $("id1").innerHTML;
}
function copyItem(id1,id2){
	
	var mes = "";
	var items2 = $(id1).getElementsByTagName("input");
	for(var i = 0 ; i < items2.length ; i++)
	{
		if(items2[i].checked == true)
		{
			mes += "<input type='checkbox' checked='true' value='"+ items2[i].value +"' onclick='copyItem(\"" + id2+ "\",\""+ id1 +"\");same(this);'>" + items2[i].value;			
		}
	}
	$(id2).innerHTML = "";
	$(id2).innerHTML += mes;
	//alert($(id2).innerHTML);
}
function same(ck){
	for(var i = 0 ; i < items.length ; i++)
	{
		if(ck.value == items[i].value)
		{
			items[i].checked = ck.checked;
		}
	}
}	
/* 鼠标拖动 */
var oDrag = "";
var ox,oy,nx,ny,dy,dx;
function drag(e,o){
	var e = e ? e : event;
	var mouseD = document.all ? 1 : 0;
	if(e.button == mouseD)
	{
		oDrag = o.parentNode;
		//alert(oDrag.id);
		ox = e.clientX;
		oy = e.clientY;		
	}
}
function dragPro(e){
	if(oDrag != "")
	{	
		var e = e ? e : event;
		//$(oDrag).style.left = $(oDrag).offsetLeft + "px";
		//$(oDrag).style.top = $(oDrag).offsetTop + "px";
		dx = parseInt($(oDrag).style.left);
		dy = parseInt($(oDrag).style.top);
		//dx = $(oDrag).offsetLeft;
		//dy = $(oDrag).offsetTop;
		nx = e.clientX;
		ny = e.clientY;
		$(oDrag).style.left = (dx + ( nx - ox )) + "px";
		$(oDrag).style.top = (dy + ( ny - oy )) + "px";
		ox = nx;
		oy = ny;
	}
}
document.onmouseup = function(){oDrag = "";}
document.onmousemove = function(event){dragPro(event);}
</SCRIPT>

	</body>
</html>
